package gulimall.pojo.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 订单确认页(结算页)响应对象
 *
 * @author HLF
 * @date 2022/8/23 20:20
 */
@Data
public class OrderConfirmVO {

    /**
     * 收货地址列表
     */
    private List<MemberAddressVO> address;


    // 所有选中的购物项
    @Getter
    @Setter
    List<OrderItemVO> item;

    // 发票记录...

    /**
     * 优惠卷信息
     */
    @Getter
    @Setter
    Integer integration;

    /**
     * 订单总额
     */
    BigDecimal total;

    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");
        if (item != null) {
            for (OrderItemVO OrderItemVO : item) {
                BigDecimal multiply = OrderItemVO.getPrice().multiply(new BigDecimal(OrderItemVO.getCount().toString()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }

    /**
     * 是否有库存
     */
    @Getter
    @Setter
    Map<Long, Boolean> stocks;


    /**
     * 应付价格
     */
    BigDecimal payPrice;

    public BigDecimal getPayPrice() {
        BigDecimal sum = new BigDecimal("0");
        if (item != null) {
            for (OrderItemVO OrderItemVO : item) {
                BigDecimal multiply = OrderItemVO.getPrice().multiply(new BigDecimal(OrderItemVO.getCount().toString()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }

    @Setter
    private Long count;

    /**
     * 遍历item 拿到商品的数量
     *
     * @return
     */
    public Long getCount() {
        Long i = 0L;
        if (item != null) {
            for (OrderItemVO OrderItemVO : item) {
                i += OrderItemVO.getCount();
            }
        }
        return i;
    }

    /**
     * 订单的防重令牌，防止用户在订单确认页多次点击提交订单
     */
    @Getter
    @Setter
    private String orderToken;
}
